<template>
    <div>
        <el-dialog v-model="dialogVisible" width="80%" align-center :close-on-click-modal="false" :show-close="false"
            :before-close="handleClose" destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>专家评审</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <el-form :model="ruleForm" :rules="rules" label-width="130px" ref="ruleFormRef">
                <!-- 评分详情 -->
                <div class="bg-white mt-[10px]">
                    <BaseHead>评分详情</BaseHead>
                    <div class="p-[10px]">
                        <el-descriptions title="" :column="1" border label-width="140">
                            <el-descriptions-item label-class-name="gdlable" label="成果名称">{{
            ruleForm.productName
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="评审意见">{{
                ruleForm.allExpertReviewVOS[0].reviewInfo
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="评审结果">{{
                ruleForm.allExpertReviewVOS[0].reviewResult == 'pass' ? '建议通过' : '不建议通过'
            }}</el-descriptions-item>
                        </el-descriptions>
                        <el-table :data="ruleForm.reviewStandardVOS" stripe style="width: 100%">
                            <el-table-column prop="name" label="一级标准" />
                            <el-table-column prop="name" label="二级标准">
                                <template #default="scope">
                                    <div v-for="item in scope.row.lvl2Names" :key="item.value" class="mt-[10px]">{{
            item.value }}</div>
                                </template>
                            </el-table-column>
                            <el-table-column prop="address" label="满分">
                                <template #default="scope">
                                    <div v-for="item in scope.row.lvl2Marks" :key="item.value" class="mt-[10px]">{{
            item.value }}</div>
                                </template>
                            </el-table-column>
                            <el-table-column prop="address" label="评审得分"> <template #default="scope">
                                    <div v-for="item in scope.row.lvl2Reviewmarks" :key="item.value" class="mt-[10px]">
                                        {{
                                        item.value }}</div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <div class="operate-btns">
                        <el-button type="primary" @click="dialogVisibleMet">关闭</el-button>
                    </div>
                </div>
            </template>
        </el-dialog>
    </div>
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import { reviewByExpert } from "@/api/achievement/cghj"
import { ElMessage, ElMessageBox } from "element-plus";
const dialogVisible = defineModel();
const ruleForm = reactive({

})

const ruleFormRef = ref()
const emit = defineEmits(['callBack']);
const ininDate = () => {
    Object.assign(ruleForm, {

    })

}
const handleClose = (done) => {
    ininDate()
    done()
}

const dialogVisibleMet = () => {
    dialogVisible.value = false;
}
const isJSON = (str) => {
    if (typeof str === 'string') {
        try {
            const obj = JSON.parse(str);
            return typeof obj === 'object' && obj !== null;
        } catch (e) {
            return false;
        }
    }
    return false;
}

const blurInput = (e, value, row, index, index1) => {
    if (Number(value) > Number(row.lvl2Marks[index].value)) {
        ElMessage({
            type: 'error',
            message: `评分不能大于满分`,
        })
        ruleForm.reviewStandardVOS[index1].lvl2Marks[index].score = row.lvl2Marks[index].value
    }
}
const getRuleForm = (i) => {
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    if (i.reviewStandardVOS && i.reviewStandardVOS.length > 0) {
        ruleForm.reviewStandardVOS = i.reviewStandardVOS.map((item, index) => {
            if (isJSON(item.lvl2Names)) {
                let lvl2Reviewmarks = []
                if (ruleForm.allExpertReviewVOS[0].reviewResultVOs && ruleForm.allExpertReviewVOS[0].reviewResultVOs.length) {
                    lvl2Reviewmarks = ruleForm.allExpertReviewVOS[0].reviewResultVOs[index].lvl2Reviewmarks.split(',').map(item => ({ value: item }))
                }
                return {
                    name: item.name,
                    id: item.id,
                    lvl2Names: JSON.parse(item.lvl2Names),
                    lvl2Marks: item.lvl2Marks.split(',').map(item => ({ value: item, score: null })),
                    lvl2Reviewmarks: lvl2Reviewmarks
                }
            } else {
                let lvl2Reviewmarks = []
                if (ruleForm.allExpertReviewVOS[0].reviewResultVOs && ruleForm.allExpertReviewVOS[0].reviewResultVOs.length) {
                    lvl2Reviewmarks = ruleForm.allExpertReviewVOS[0].reviewResultVOs[index].lvl2Reviewmarks.split(',').map(item => ({ value: item }))
                }
                return {
                    name: item.name,
                    id: item.id,
                    lvl2Names: item.lvl2Names.split(',').map(item => ({ value: item })),
                    lvl2Marks: item.lvl2Marks.split(',').map(item => ({ value: item, score: null })),
                    lvl2Reviewmarks: lvl2Reviewmarks
                }
            }

        })
    }
    console.log(ruleForm, 'ruleForm')
}
defineExpose({
    getRuleForm
})
</script>

<style scoped lang="scss">
@import url("@/views/achievement/index.scss");
</style>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>